package com.xwh.week5;

public class Pr_1 {
    static boolean[] exit=new boolean[10];
    static int ans;
    public static void main(String[] args) {

           for(int i=9;i>=4;i--) {
               pandigital(0, 0, i);
               if(ans!=0)
                   break;
           }

        System.out.println(ans);
    }
    public static void pandigital(int step,int sum,int n){
        if(step==n){
            if(isPrime(sum)){
                ans=Math.max(ans,sum);
                return;
            }
        }
        for(int i=n;i>0;i--){
            if(!exit[i]){
                sum=sum*10+i;
                exit[i]=true;
                pandigital(step+1,sum,n);
                sum/=10;
                exit[i]=false;
            }
        }
        return;
    }
    public static boolean isPrime(int n){
        int flag=1;
        for(int i=2;flag!=0&&i<=Math.sqrt(n);i++){
            flag=n%i;
        }
        return flag!=0;
    }
}
